package com.njmd.mdbs.web.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.njmd.framework.dao.BaseHibernateDAO;
import com.njmd.mdbs.web.entity.sys.SysLoginRole;

@Repository
public class SysLoginRoleDAO extends BaseHibernateDAO<SysLoginRole, Long>
{
	public List<SysLoginRole> findByLoginId(Long loginId)
	{
		return this.findByProperty("sysLogin.loginId", loginId);
	}
	
	public void deleteByLoginId(Long loginId)
	{
		List<SysLoginRole> list = this.findByProperty("sysLogin.loginId", loginId);
		for (SysLoginRole sysLoginRole : list)
		{
			this.delete(sysLoginRole);
		}
	}
	
	/**
	 * <p>
	 * Description:[根据角色id，去判断是否有用户跟此角色关联]
	 * </p>
	 * 
	 * @param roleId
	 * @return
	 */
	public boolean findLoginByRole(Long[] roleId)
	{
		String hql = "from SysLoginRole model where model.sysRole.roleId in (:roleIds)";
		Map m = new HashMap();
		m.put("roleIds", roleId);
		List<SysLoginRole> list = this.findByHql(hql, m);
		if (list == null || list.isEmpty())
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
